| Server IP : 121.121.20.254 / Your IP : 216.73.216.202 Web Server : Microsoft-IIS/10.0 System : Windows NT WEB-SERVER 10.0 build 20348 (Windows Server 2022) AMD64 User : IUSR ( 0) PHP Version : 8.3.28 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/Program Files/LibreOffice/help/en-US/text/sbasic/python/ |
Upload File : |
<!DOCTYPE html>
<html lang="en-US" dir="ltr">
<head>
<base href="../../../../">
<noscript><meta http-equiv="refresh" content="0; URL=../../../../en-US/noscript.html"></noscript>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Python : Platform class</title>
<link rel="shortcut icon" href="media/navigation/favicon.ico">
<link type="text/css" href="normalize.css" rel="Stylesheet">
<link type="text/css" href="prism.css" rel="Stylesheet">
<link type="text/css" href="default.css" rel="Stylesheet">
<script type="text/javascript" src="polyfills.js"></script><script type="text/javascript" src="languages.js"></script><script type="text/javascript" src="en-US/langnames.js"></script><script type="text/javascript" src="flexsearch.debug.js"></script><script type="text/javascript" src="prism.js"></script><script type="text/javascript" src="help2.js" defer></script><script type="text/javascript" src="a11y-toggle.js" defer></script><script type="text/javascript" src="paginathing.js" defer></script><script type="text/javascript" src="en-US/bookmarks.js" defer></script><script type="text/javascript" src="en-US/contents.js" defer></script><script type="text/javascript" src="help.js" defer></script><meta name="viewport" content="width=device-width,initial-scale=1">
</head>
<body>
<header id="TopLeftHeader"><a class="symbol" href="en-US/text/shared/05/new_help.html"><div></div></a><a class="logo" href="en-US/text/shared/05/new_help.html"><p dir="auto">LibreOffice 24.2 Help</p></a><div class="dropdowns"><div class="modules">
<button type="button" data-a11y-toggle="modules-nav" id="modules" aria-haspopup="true" aria-expanded="false" aria-controls="modules-nav">Module</button><nav id="modules-nav" hidden=""></nav>
</div></div></header><aside class="leftside"><input id="accordion-1" name="accordion-menu" type="checkbox"><label for="accordion-1" dir="auto">Contents</label><div id="Contents" class="contents-treeview"></div></aside><div id="SearchFrame"><div id="Bookmarks">
<input id="search-bar" type="search" class="search" placeholder="Search in bookmarks for chosen module" dir="auto"><div class="nav-container" tabindex="0"><nav class="index" dir="auto"></nav></div>
</div></div>
<div id="DisplayArea" itemprop="softwareHelp" itemscope="true" itemtype="http://schema.org/SoftwareApplication">
<a name="N0508"></a>
<meta itemprop="keywords" content="Platform,isLinux">
<meta itemprop="keywords" content="Platform,isMacOsX">
<meta itemprop="keywords" content="Platform,isWindows">
<meta itemprop="keywords" content="Platform,ComputerName">
<meta itemprop="keywords" content="Platform,OSName">
<meta itemprop="keywords" content="API,ConfigurationAccess">
<meta itemprop="keywords" content="Tools,GetRegistryContent">
<h1 id="N0509" dir="auto">
<a name="pythonplatform"></a>Identifying the operating system</h1>
<p id="N0510" class="paragraph" dir="auto">Identifying the operating system can be performed with Python or Basic language.</p>
<div class="note">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/note.svg" alt="note" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="N0511" dir="auto">ComputerName property is solely available for Windows. Basic calls to Python macros help overcome LibreOffice Basic limitations.</p></div>
</div>
<br>
<h2 id="N0512" dir="auto">Using a Python class:</h2>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
""" the_module """
import os, platform
class Platform():
@property
def ComputerName(self): return platform.node()
@property
def DirSeparator(self): return os.sep
@property
def isLinux(self): return (self.OSName=='Linux')
@property
def isMacOSX(self): return (self.OSName=='Darwin')
@property
def isWindows(self): return (self.OSName=='Windows')
@property
def OSName(self): return platform.system()
@property
def PathDelimiter(self): return os.pathsep
</code></pre></div>
<h2 id="N0529" dir="auto">Using a Basic classmodule:</h2>
<div class="tip">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/tip.svg" alt="tip" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="NO529b" dir="auto">LibreOffice Basic lacks MacOS X native recognition. Platform identification is possible using LibreOffice Application Programming Interface (API).</p></div>
</div>
<br>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
Option Compatible
Option ClassModule
Option Explicit
Public Property Get ComputerName As String
If isWindows Then ComputerName = Environ("ComputerName")
End Property ' Platform.ComputerName
Public Property Get DirSeparator As String
DirSeparator = GetPathSeparator()
End Property ' Platform.DirSeparator
Public Property Get IsLinux As Boolean
isLinux = ( GetGUIType()=4 ) ' Applies to macOS as well
End Property ' Platform.isLinux
Public Property Get IsMacOSX As Boolean
isMacOSX = ( OSName="MAC" )
End Property ' Platform.isMacOSX
Public Property Get IsWindows As Boolean
isWindows = ( GetGUIType()=1 )
End Property ' Platform.isWindows
Public Property Get OSName As String
' Return platform name as "MAC", "UNIX", "WIN"
' Inferred from "Tools.UCB.ShowHelperDialog" function
With GlobalScope.Basiclibraries
If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")
End With
Dim keyNode As Object ' com.sun.star.configuration.ConfigurationAccess
keyNode = Tools.Misc.GetRegistryKeyContent("org.openoffice.Office.Common/Help")
OSName = keyNode.GetByName("System")
End Property ' Platform.OSName
Public Property Get PathDelimiter As String
Select Case OSName
Case "MAC", "UNIX" : PathDelimiter = ":"
Case "WIN" : PathDelimiter = ";"
End Select
End Property ' Platform.PathDelimiter
</code></pre></div>
<h2 id="N0564" dir="auto">Examples:</h2>
<p id="N0565" class="paragraph" dir="auto">With Python</p>
<p id="N0566" class="paragraph" dir="auto"><span class="literal">>>> from < the_module > import Platform</span></p>
<p id="N0567" class="paragraph" dir="auto"><span class="literal">>>> print(Platform().isMacOSX) # object property</span></p>
<p id="N0568" class="paragraph" dir="auto"><span class="literal">True</span></p>
<p id="N0569" class="paragraph" dir="auto"><span class="literal">>>> input(Platform().OSName) # object property</span></p>
<p id="N0570" class="paragraph" dir="auto"><span class="literal">Darwin</span></p>
<p id="N0571" class="paragraph" dir="auto">
From <span class="menuitem">Tools – Macros - Run Macro...</span> menu.</p>
<div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
from < the_module > import Platform
import screen_io as ui
p = Platform()
ui.MsgBox(''.join(['isMacOS: ',str(p.isMacOSX)]),0,p.OSName)
</code></pre></div>
<p id="N0576" class="paragraph" dir="auto">With LibreOffice Basic</p>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
Sub Platform_example()
Dim p As New Platform ' instance of Platform class
MsgBox p.isLinux ' object property
Print p.isWindows, p.OSName ' object properties
End Sub ' Platform_example
</code></pre></div>
<a name="relatedtopics"></a><div class="relatedtopics">
<p class="related" itemprop="mentions" dir="auto"><a name="related"></a><span class="emph">Related Topics</span>
</p>
<div class="relatedbody" itemprop="mentions">
<div class="embedded"><p class="embedded" dir="auto"><a target="_top" href="en-US/text/sbasic/python/python_screen.html">Input/Output to Screen</a></p></div>
<div class="embedded"><p class="embedded" dir="auto"><a target="_top" href="en-US/text/sbasic/shared/03132100.html">GetGuiType Function</a></p></div>
<div class="embedded"><p class="embedded" dir="auto"><a target="_top" href="en-US/text/sbasic/shared/GetPathSeparator.html">GetPathSeparator Function</a></p></div>
<div class="embedded"><p class="embedded" dir="auto"><a target="_top" href="en-US/text/sbasic/guide/basic_2_python.html">Calling Python Scripts from Basic</a></p></div>
<div class="embedded"><p class="embedded" dir="auto"><a target="_top" href="en-US/text/sbasic/python/python_examples.html">Python programming examples</a></p></div>
<div class="embedded"><p class="embedded" dir="auto"><a target="_top" href="en-US/text/sbasic/python/main0000.html">LibreOffice Python Scripts Help</a></p></div>
</div>
</div>
</div>
<div id="DonationFrame"></div>
<footer><div id="DEBUG" class="debug">
<h3 class="bug">Help content debug info:</h3>
<p dir="auto">This page is: <a href="https://opengrok.libreoffice.org/xref/help/source/text/sbasic/python/python_platform.xhp" target="_blank">/text/sbasic/python/python_platform.xhp</a></p>
<p dir="auto">Title is: Python : Platform class</p>
<p id="bm_module" dir="auto"></p>
<p id="bm_system" dir="auto"></p>
<p id="bm_HID" dir="auto"></p>
</div></footer>
</body>
</html>